package com.example.demo.utils;

public class BackResult {

    private static final int FAIL_CODE = 400;
    private static final int SUCCESS_CODE = 200;

    //成功返回
    public static Object success(Object data){
        return msg(SUCCESS_CODE,"返回成功",data);
    }
    public static Object success(){
        return msg(SUCCESS_CODE,"",null);
    }

    //失败返回
    public static Object fail(){
        return msg(FAIL_CODE,"服务器错误",null);
    }
    public static Object fail(String msg){
        return msg(FAIL_CODE,msg,null);
    }
    //自定义返回
    public static Object msg(int code,String msg,Object data){
        return new BackEntity(code,msg,data);
    }

    static class BackEntity{
        private int code;
        private String msg;
        private Object data;
        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        public Object getData() {
            return data;
        }

        public void setData(Object data) {
            this.data = data;
        }

        public BackEntity(int code, String msg, Object data) {
            this.code = code;
            this.msg = msg;
            this.data = data;
        }
        public BackEntity(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }
        public BackEntity() {
        }
    }
}
